﻿using Estsh.Core.Model.EnumUtil;
using Estsh.Core.Models;
using Estsh.Core.Quartz.BaseService;
using Estsh.Core.Util;
using Estsh.Core.Wms.IRepositories;

namespace Estsh.Core.Wms.Jobs
{
    /// <summary>
    /// 从SAP传递供应商基本信息到WMS
    /// </summary>
    public class InterfaceSupplierMasterJob : IJobService
    {
        private readonly IInterfaceMasterRepository repository;


        public InterfaceSupplierMasterJob(IInterfaceMasterRepository _repository)
        {
            this.repository = _repository;

        }

        public string ExecuteService(string parameter)
        {
            try
            {
                List<SapSu> sapSus = repository.GetSupplierMasterInfo();
                if (sapSus.Count <= 0)
                {
                    return "没有待处理的供应商主数据！";
                }
                bool bl = repository.InsertSupplierMasterInfo(sapSus);
                if (bl == true)
                {
                    return "供应商主数据同步成功！";
                }
                else
                {
                    return "供应商主数据同步失败！";
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("供应商主数据同步错误！" + ex);
                return "供应商主数据同步错误！" + ex.Message;
            }
        }

    }
}
